package view;

import HibernateConfig.HibernateUtil;
import java.awt.event.KeyEvent;
import java.util.ArrayList;
import java.util.Iterator;
import java.util.List;
import java.util.Vector;
import javax.swing.JOptionPane;
import javax.swing.table.DefaultTableModel;
import model.Cliente;
import org.hibernate.Session;
import org.hibernate.Transaction;

public class BusquedaCliente extends javax.swing.JFrame {

    private Registro ventanaPadre;
    Vector columnasTablaClientes; //cabecera de la tabla
    DefaultTableModel modeloTablaClientes;   //modelo para la tabla clientes
    List<Cliente> listaFilasTablaClientes; //lista de Cliente que contendra la tabla clientes

    public BusquedaCliente(Registro ventanaPadre) {
        initComponents();
        this.ventanaPadre = ventanaPadre;
        //Inicializo radiobutton
        this.rdPersona.doClick();

        //Inicializo la tabla
        listaFilasTablaClientes = new ArrayList<Cliente>(); //lista de clientes para la tabla
        columnasTablaClientes = new Vector(); //Cabecera
        columnasTablaClientes.add("Id Cliente");
        columnasTablaClientes.add("Nombre/Razon Social");
        columnasTablaClientes.add("Doc. Identidad");
        columnasTablaClientes.add("Correo");
        columnasTablaClientes.add("Telefono");
        modeloTablaClientes = new DefaultTableModel(this.columnasTablaClientes, 0) {
            public boolean isCellEditable(int row, int column) { // para que no se pueda editar directamente la tabla
                return false;
            }
        };

        this.tblResult.setModel(modeloTablaClientes);
        this.tblResult.setCellSelectionEnabled(false); // para que no se puedan seleccionar celdas individuales
        this.tblResult.setRowSelectionAllowed(true);   // para que se seleccione la fila entera

        //PRUEBAS TABLA CLIENTES
//        Cliente clienteTemp = new Cliente();
//        clienteTemp.setIdCliente(14);
//        clienteTemp.setNombres("jeancarlo");
//        clienteTemp.setDni("45496338");
//        clienteTemp.setEmail("@pucp");
//        clienteTemp.setTelefono("989459495");
//        
//        listaFilasTablaClientes.add(clienteTemp);
//        
//        Cliente clienteTemp2 = new Cliente();
//        clienteTemp2.setIdCliente(8);
//        clienteTemp2.setNombres("eve");
//        clienteTemp2.setDni("44456732");
//        clienteTemp2.setEmail("@pucp.pe");
//        clienteTemp2.setTelefono("989948916");
//        
//        listaFilasTablaClientes.add(clienteTemp2);
//        
//        for (int i = 0; i < listaFilasTablaClientes.size(); i++) {
//            Object[] o = new Object[5];
//            o[0] = listaFilasTablaClientes.get(i).getIdCliente();
//            o[1] = listaFilasTablaClientes.get(i).getNombres();
//            o[2] = listaFilasTablaClientes.get(i).getDni();
//            o[3] = listaFilasTablaClientes.get(i).getEmail();
//            o[4] = listaFilasTablaClientes.get(i).getTelefono();      
//            modeloTablaClientes.addRow(o);
//        }
    }

    private BusquedaCliente() {

    }

    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        buttonGroup1 = new javax.swing.ButtonGroup();
        jPanel2 = new javax.swing.JPanel();
        jScrollPane1 = new javax.swing.JScrollPane();
        tblResult = new javax.swing.JTable();
        btnAceptar = new javax.swing.JButton();
        btnCancelar = new javax.swing.JButton();
        jPanel3 = new javax.swing.JPanel();
        btnBuscar = new javax.swing.JButton();
        btnLimpiar = new javax.swing.JButton();
        rdPersona = new javax.swing.JRadioButton();
        rdEmpresa = new javax.swing.JRadioButton();
        lblNombres = new javax.swing.JLabel();
        txtNombre = new javax.swing.JTextField();
        txtApPat = new javax.swing.JTextField();
        txtDNI = new javax.swing.JTextField();
        lblApPat = new javax.swing.JLabel();
        lblDni = new javax.swing.JLabel();

        setDefaultCloseOperation(javax.swing.WindowConstants.DO_NOTHING_ON_CLOSE);
        setTitle("Búsqueda de Cliente");
        setResizable(false);
        getContentPane().setLayout(new org.netbeans.lib.awtextra.AbsoluteLayout());

        jPanel2.setBorder(javax.swing.BorderFactory.createTitledBorder("Resultados"));

        tblResult.setFont(new java.awt.Font("Arial", 0, 11)); // NOI18N
        tblResult.setModel(new javax.swing.table.DefaultTableModel(
            new Object [][] {
                {null, null, null, null, null},
                {null, null, null, null, null},
                {null, null, null, null, null},
                {null, null, null, null, null}
            },
            new String [] {
                "Id Cliente", "Nombre", "DNI", "Correo", "Teléfono"
            }
        ));
        jScrollPane1.setViewportView(tblResult);

        btnAceptar.setFont(new java.awt.Font("Arial", 0, 11)); // NOI18N
        btnAceptar.setIcon(new javax.swing.ImageIcon(getClass().getResource("/resources/aceptar.png"))); // NOI18N
        btnAceptar.setText("Aceptar");
        btnAceptar.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                btnAceptarActionPerformed(evt);
            }
        });

        btnCancelar.setFont(new java.awt.Font("Arial", 0, 11)); // NOI18N
        btnCancelar.setIcon(new javax.swing.ImageIcon(getClass().getResource("/resources/Cancelar.png"))); // NOI18N
        btnCancelar.setText("Cancelar");
        btnCancelar.addMouseListener(new java.awt.event.MouseAdapter() {
            public void mouseClicked(java.awt.event.MouseEvent evt) {
                btnCancelarMouseClicked(evt);
            }
        });
        btnCancelar.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                btnCancelarActionPerformed(evt);
            }
        });

        javax.swing.GroupLayout jPanel2Layout = new javax.swing.GroupLayout(jPanel2);
        jPanel2.setLayout(jPanel2Layout);
        jPanel2Layout.setHorizontalGroup(
            jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addComponent(jScrollPane1, javax.swing.GroupLayout.DEFAULT_SIZE, 528, Short.MAX_VALUE)
            .addGroup(jPanel2Layout.createSequentialGroup()
                .addGap(130, 130, 130)
                .addComponent(btnAceptar)
                .addGap(32, 32, 32)
                .addComponent(btnCancelar)
                .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
        );
        jPanel2Layout.setVerticalGroup(
            jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel2Layout.createSequentialGroup()
                .addComponent(jScrollPane1, javax.swing.GroupLayout.PREFERRED_SIZE, 128, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(btnAceptar)
                    .addComponent(btnCancelar))
                .addGap(0, 0, Short.MAX_VALUE))
        );

        getContentPane().add(jPanel2, new org.netbeans.lib.awtextra.AbsoluteConstraints(10, 206, -1, -1));

        jPanel3.setBorder(javax.swing.BorderFactory.createTitledBorder("Criterios de Búsqueda"));
        jPanel3.setFont(new java.awt.Font("Arial", 0, 11)); // NOI18N

        btnBuscar.setFont(new java.awt.Font("Arial", 0, 11)); // NOI18N
        btnBuscar.setIcon(new javax.swing.ImageIcon(getClass().getResource("/resources/buscar.png"))); // NOI18N
        btnBuscar.setText("Buscar");
        btnBuscar.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                btnBuscarActionPerformed(evt);
            }
        });

        btnLimpiar.setFont(new java.awt.Font("Arial", 0, 11)); // NOI18N
        btnLimpiar.setIcon(new javax.swing.ImageIcon(getClass().getResource("/resources/Limpiar.png"))); // NOI18N
        btnLimpiar.setText("Limpiar");
        btnLimpiar.addMouseListener(new java.awt.event.MouseAdapter() {
            public void mouseClicked(java.awt.event.MouseEvent evt) {
                btnLimpiarMouseClicked(evt);
            }
        });
        btnLimpiar.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                btnLimpiarActionPerformed(evt);
            }
        });

        buttonGroup1.add(rdPersona);
        rdPersona.setFont(new java.awt.Font("Arial", 0, 11)); // NOI18N
        rdPersona.setText("Persona");
        rdPersona.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                rdPersonaActionPerformed(evt);
            }
        });

        buttonGroup1.add(rdEmpresa);
        rdEmpresa.setFont(new java.awt.Font("Arial", 0, 11)); // NOI18N
        rdEmpresa.setText("Empresa");
        rdEmpresa.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                rdEmpresaActionPerformed(evt);
            }
        });

        lblNombres.setFont(new java.awt.Font("Arial", 0, 11)); // NOI18N
        lblNombres.setText("Nombres:");

        txtNombre.setFont(new java.awt.Font("Arial", 0, 11)); // NOI18N
        txtNombre.addKeyListener(new java.awt.event.KeyAdapter() {
            public void keyTyped(java.awt.event.KeyEvent evt) {
                txtNombreKeyTyped(evt);
            }
        });

        txtApPat.setFont(new java.awt.Font("Arial", 0, 11)); // NOI18N
        txtApPat.addKeyListener(new java.awt.event.KeyAdapter() {
            public void keyTyped(java.awt.event.KeyEvent evt) {
                txtApPatKeyTyped(evt);
            }
        });

        txtDNI.setFont(new java.awt.Font("Arial", 0, 11)); // NOI18N
        txtDNI.addKeyListener(new java.awt.event.KeyAdapter() {
            public void keyTyped(java.awt.event.KeyEvent evt) {
                txtDNIKeyTyped(evt);
            }
        });

        lblApPat.setFont(new java.awt.Font("Arial", 0, 11)); // NOI18N
        lblApPat.setText("Apellido Paterno:");

        lblDni.setFont(new java.awt.Font("Arial", 0, 11)); // NOI18N
        lblDni.setText("Doc. Identidad:");

        javax.swing.GroupLayout jPanel3Layout = new javax.swing.GroupLayout(jPanel3);
        jPanel3.setLayout(jPanel3Layout);
        jPanel3Layout.setHorizontalGroup(
            jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel3Layout.createSequentialGroup()
                .addGap(10, 10, 10)
                .addGroup(jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(jPanel3Layout.createSequentialGroup()
                        .addGroup(jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addComponent(rdPersona)
                            .addComponent(lblNombres))
                        .addGap(34, 34, 34)
                        .addGroup(jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addComponent(rdEmpresa)
                            .addComponent(txtNombre, javax.swing.GroupLayout.PREFERRED_SIZE, 120, javax.swing.GroupLayout.PREFERRED_SIZE))
                        .addGap(165, 165, 165)
                        .addComponent(btnBuscar))
                    .addGroup(jPanel3Layout.createSequentialGroup()
                        .addGroup(jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addComponent(lblApPat)
                            .addComponent(lblDni, javax.swing.GroupLayout.PREFERRED_SIZE, 81, javax.swing.GroupLayout.PREFERRED_SIZE))
                        .addGap(18, 18, 18)
                        .addGroup(jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addComponent(txtApPat, javax.swing.GroupLayout.PREFERRED_SIZE, 240, javax.swing.GroupLayout.PREFERRED_SIZE)
                            .addComponent(txtDNI, javax.swing.GroupLayout.PREFERRED_SIZE, 119, javax.swing.GroupLayout.PREFERRED_SIZE))
                        .addGap(45, 45, 45)
                        .addComponent(btnLimpiar))))
        );
        jPanel3Layout.setVerticalGroup(
            jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel3Layout.createSequentialGroup()
                .addGap(13, 13, 13)
                .addGroup(jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(jPanel3Layout.createSequentialGroup()
                        .addComponent(rdPersona)
                        .addGap(13, 13, 13)
                        .addComponent(lblNombres))
                    .addGroup(jPanel3Layout.createSequentialGroup()
                        .addComponent(rdEmpresa)
                        .addGap(9, 9, 9)
                        .addComponent(txtNombre, javax.swing.GroupLayout.PREFERRED_SIZE, 22, javax.swing.GroupLayout.PREFERRED_SIZE))
                    .addGroup(jPanel3Layout.createSequentialGroup()
                        .addGap(21, 21, 21)
                        .addComponent(btnBuscar)))
                .addGap(8, 8, 8)
                .addGroup(jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(jPanel3Layout.createSequentialGroup()
                        .addGap(1, 1, 1)
                        .addComponent(lblApPat, javax.swing.GroupLayout.PREFERRED_SIZE, 23, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addGap(11, 11, 11)
                        .addComponent(lblDni, javax.swing.GroupLayout.PREFERRED_SIZE, 23, javax.swing.GroupLayout.PREFERRED_SIZE))
                    .addGroup(jPanel3Layout.createSequentialGroup()
                        .addComponent(txtApPat, javax.swing.GroupLayout.PREFERRED_SIZE, 24, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addGap(11, 11, 11)
                        .addComponent(txtDNI, javax.swing.GroupLayout.PREFERRED_SIZE, 24, javax.swing.GroupLayout.PREFERRED_SIZE))
                    .addGroup(jPanel3Layout.createSequentialGroup()
                        .addGap(11, 11, 11)
                        .addComponent(btnLimpiar))))
        );

        getContentPane().add(jPanel3, new org.netbeans.lib.awtextra.AbsoluteConstraints(10, 11, 540, 170));

        setSize(new java.awt.Dimension(576, 458));
        setLocationRelativeTo(null);
    }// </editor-fold>//GEN-END:initComponents

    private void btnCancelarMouseClicked(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_btnCancelarMouseClicked
        this.dispose();
    }//GEN-LAST:event_btnCancelarMouseClicked

    private void btnLimpiarMouseClicked(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_btnLimpiarMouseClicked
        txtDNI.setText("");
        txtApPat.setText("");
        txtNombre.setText("");
        tblResult.removeAll();
    }//GEN-LAST:event_btnLimpiarMouseClicked

    private void btnCancelarActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnCancelarActionPerformed
        // TODO add your handling code here:
    }//GEN-LAST:event_btnCancelarActionPerformed

    // click a boton Aceptar
    private void btnAceptarActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnAceptarActionPerformed
        
        if (this.tblResult.getSelectedRow() == -1){//no se selecciono niguna fila
            
            JOptionPane.showMessageDialog(null, "Debe seleccionar un cliente","Error",JOptionPane.ERROR_MESSAGE);
            
        }else{// se selecciono alguna fila
            int i = tblResult.getSelectedRow();
            Cliente cliente = listaFilasTablaClientes.get(i);
            this.ventanaPadre.agregarCliente(cliente, rdPersona.isSelected());

            this.dispose();
        }

    }//GEN-LAST:event_btnAceptarActionPerformed

    // click en radiobutton cliente persona
    private void rdPersonaActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_rdPersonaActionPerformed

        this.lblApPat.setText("Apellido Paterno:");
        this.lblDni.setText("Doc. Identidad");
        this.lblNombres.setText("Nombres:");
        this.lblApPat.setVisible(true);
        this.txtApPat.setVisible(true);

        this.limpiarTxt();

    }//GEN-LAST:event_rdPersonaActionPerformed

    // click en radiobutton cliente empresa
    private void rdEmpresaActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_rdEmpresaActionPerformed
        this.lblApPat.setVisible(false);
        this.txtApPat.setVisible(false);
        this.lblDni.setText("RUC:");
        this.lblDni.setAlignmentY(100);//no funciona
        this.lblNombres.setText("Razón Social");
        this.lblNombres.setAlignmentY(100);//no funciona

        this.limpiarTxt();
    }//GEN-LAST:event_rdEmpresaActionPerformed

    // click en boton Limpiar
    private void btnLimpiarActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnLimpiarActionPerformed
        for (int i = listaFilasTablaClientes.size() - 1; i >= 0; i--) {
            modeloTablaClientes.removeRow(i);
        }
        listaFilasTablaClientes.clear();
        
        this.limpiarTxt();
    }//GEN-LAST:event_btnLimpiarActionPerformed

    private void btnBuscarActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnBuscarActionPerformed

        Cliente clienteTemp;
        //hacer conexion
        Session sesion = HibernateUtil.getSessionFactory().openSession();
        Transaction transaccion = sesion.beginTransaction();
        String hql = "FROM Cliente c";
        int nFiltros = 0;

        //Borramos las busquedas previas
        for (int i = listaFilasTablaClientes.size() - 1; i >= 0; i--) {
            modeloTablaClientes.removeRow(i);
        }
        listaFilasTablaClientes.clear();

        if (rdPersona.isSelected()) {//Buscar por persona natural
            hql = hql.concat(" WHERE tipo= 'natural'");
            if (txtNombre.getText().length() > 0) {                
                //hql=hql.concat("c.nombres like '%").concat(txtNombre.getText()).concat("%'");
                hql = hql.concat(" and c.nombres like '%").concat(txtNombre.getText()).concat("%'");
                nFiltros++;
            }
            if (txtApPat.getText().length() > 0) {
                System.out.println(nFiltros);
//                if (nFiltros > 0) {
//                    hql = hql.concat(" and ");
//                }                
                hql = hql.concat(" and c.apPaterno like '%").concat(txtApPat.getText()).concat("%'");
                nFiltros++;
            }
            if (txtDNI.getText().length() > 0) {
//                if (nFiltros > 0) {
//                    hql = hql.concat(" and ");
//                }                        
                hql = hql.concat(" and c.dni='").concat(txtDNI.getText()).concat("'");
                nFiltros++;
            }
        } else {//Buscar por empresa
            hql = hql.concat(" WHERE tipo='empresa'");
            if (txtNombre.getText().length() > 0) {
                hql = hql.concat(" and c.razonSocial like '%").concat(txtNombre.getText()).concat("%'");
                nFiltros++;
            }
            if (txtDNI.getText().length() > 0) {
//                if (nFiltros > 0) {
//                    hql = hql.concat(" and ");
//                }                
                hql = hql.concat(" and c.ruc='").concat(txtDNI.getText()).concat("'");
                nFiltros++;
            }
        }
        //System.out.println(hql);
        List clientes = sesion.createQuery(hql).list();   // query para obtener las ciudades
        Iterator iterador = clientes.iterator();    // iterador de la lista de clientes

        while (iterador.hasNext()) {   //mientras hayan clientes en el iterador
            //creo objeto cliente
            clienteTemp = (Cliente) iterador.next();   // obtengo un cliente de la lista de ciudades
            listaFilasTablaClientes.add(clienteTemp);   //agrego nodo a la lista de nodos
        }

        for (int i = 0; i < listaFilasTablaClientes.size(); i++) {
            Object[] o = new Object[5];
            o[0] = listaFilasTablaClientes.get(i).getIdCliente();
            o[1] = listaFilasTablaClientes.get(i).getCadenaNombreCompletoCliente();
            if (rdPersona.isSelected()) {
                o[2] = listaFilasTablaClientes.get(i).getDni();
            } else {
                o[2] = listaFilasTablaClientes.get(i).getRuc();
            }
            o[3] = listaFilasTablaClientes.get(i).getEmail();
            o[4] = listaFilasTablaClientes.get(i).getTelefono();
            modeloTablaClientes.addRow(o);
        }

        sesion.close(); // cierro la BD
    }//GEN-LAST:event_btnBuscarActionPerformed

    private void txtNombreKeyTyped(java.awt.event.KeyEvent evt) {//GEN-FIRST:event_txtNombreKeyTyped
//        char vChar = evt.getKeyChar();
//        if (!(Character.isAlphabetic(vChar)
//                || (vChar == KeyEvent.VK_BACK_SPACE)
//                || (vChar == KeyEvent.VK_DELETE))) {
//            evt.consume();
//        }
        char vChar = evt.getKeyChar();
        if(rdPersona.isSelected()){
            if (!(Character.isAlphabetic(vChar)
                    || (Character.isSpaceChar(vChar))
                    || (vChar == KeyEvent.VK_BACK_SPACE)
                    || (vChar == KeyEvent.VK_DELETE) )) {
                evt.consume();
            }
        }else if(rdEmpresa.isSelected()){
            if (!(Character.isAlphabetic(vChar)
                    || (Character.isSpaceChar(vChar))
                    || (vChar == KeyEvent.VK_BACK_SPACE)
                    || (vChar == KeyEvent.VK_DELETE)
                    || Character.isDigit(vChar)
                    || (vChar == KeyEvent.VK_PERIOD))) {
                evt.consume();
            }
        }
    }//GEN-LAST:event_txtNombreKeyTyped

    private void txtApPatKeyTyped(java.awt.event.KeyEvent evt) {//GEN-FIRST:event_txtApPatKeyTyped
        char vChar = evt.getKeyChar();
        if (!(Character.isAlphabetic(vChar)
                || (vChar == KeyEvent.VK_BACK_SPACE)
                || (vChar == KeyEvent.VK_DELETE))) {
            evt.consume();
        }
    }//GEN-LAST:event_txtApPatKeyTyped

    private void txtDNIKeyTyped(java.awt.event.KeyEvent evt) {//GEN-FIRST:event_txtDNIKeyTyped
        char vChar = evt.getKeyChar();
        if (!(Character.isDigit(vChar)
                || (vChar == KeyEvent.VK_BACK_SPACE)
                || (vChar == KeyEvent.VK_DELETE))) {
            evt.consume();
        }
    }//GEN-LAST:event_txtDNIKeyTyped

    /**
     * @param args the command line arguments
     */
    public static void main(String args[]) {
        /* Set the Nimbus look and feel */
        //<editor-fold defaultstate="collapsed" desc=" Look and feel setting code (optional) ">
        /* If Nimbus (introduced in Java SE 6) is not available, stay with the default look and feel.
         * For details see http://download.oracle.com/javase/tutorial/uiswing/lookandfeel/plaf.html 
         */
        try {
            for (javax.swing.UIManager.LookAndFeelInfo info : javax.swing.UIManager.getInstalledLookAndFeels()) {
                if ("Nimbus".equals(info.getName())) {
                    javax.swing.UIManager.setLookAndFeel(info.getClassName());
                    break;
                }
            }
        } catch (ClassNotFoundException ex) {
            java.util.logging.Logger.getLogger(BusquedaCliente.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        } catch (InstantiationException ex) {
            java.util.logging.Logger.getLogger(BusquedaCliente.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        } catch (IllegalAccessException ex) {
            java.util.logging.Logger.getLogger(BusquedaCliente.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        } catch (javax.swing.UnsupportedLookAndFeelException ex) {
            java.util.logging.Logger.getLogger(BusquedaCliente.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        }
        //</editor-fold>

        /* Create and display the form */
        java.awt.EventQueue.invokeLater(new Runnable() {
            public void run() {
                new BusquedaCliente().setVisible(true);
            }
        });
    }

    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JButton btnAceptar;
    private javax.swing.JButton btnBuscar;
    private javax.swing.JButton btnCancelar;
    private javax.swing.JButton btnLimpiar;
    private javax.swing.ButtonGroup buttonGroup1;
    private javax.swing.JPanel jPanel2;
    private javax.swing.JPanel jPanel3;
    private javax.swing.JScrollPane jScrollPane1;
    private javax.swing.JLabel lblApPat;
    private javax.swing.JLabel lblDni;
    private javax.swing.JLabel lblNombres;
    private javax.swing.JRadioButton rdEmpresa;
    private javax.swing.JRadioButton rdPersona;
    private javax.swing.JTable tblResult;
    private javax.swing.JTextField txtApPat;
    private javax.swing.JTextField txtDNI;
    private javax.swing.JTextField txtNombre;
    // End of variables declaration//GEN-END:variables

    // metodo para limpiar los textbox
    private void limpiarTxt() {
        this.txtApPat.setText("");
        this.txtDNI.setText("");
        this.txtNombre.setText("");
    }
}
